﻿using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;

namespace Ldy.Core
{
    /// <summary>
    /// lil 系统功能类 {21EB22A9-1A47-4EDB-BD53-FE030755C7D8}
    /// </summary>
    public class Sys
    {
        /// <summary>
        /// 获取系统配置参数
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetAppSettings(string key)
        {
            return System.Configuration.ConfigurationManager.AppSettings[key];
        }

        /// <summary>
        /// 获取系统数据库字符串
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetConnectionString(string key)
        {
            return System.Configuration.ConfigurationManager.ConnectionStrings[key]?.ConnectionString;
        }

        /// <summary>
        /// 获取本机IP地址
        /// </summary>
        /// <returns></returns>
        public static string GetIPAddress()
        {
            IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress p in IpEntry.AddressList)
            {
                if (p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    return p.ToString();
                }
            }
            return string.Empty;
        }

        /// <summary>
        /// 获取MAC地址
        /// </summary>
        /// <returns></returns>
        public static List<string> GetMacAddress()
        {
            List<string> macs = new List<string>();
            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface ni in interfaces)
            {
                macs.Add(ni.GetPhysicalAddress().ToString());
            }
            return macs;
        }

    }
}
